package cn.itcast.hotel.listener;

import cn.itcast.hotel.constant.MqConstant;
import cn.itcast.hotel.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * hotel酒店监听器
 *
 * @Author XiaoJiangShi
 * @Date 2022/8/9 10:04
 * @Blog blog.XiaoJiangShi.net/996.mba
 * @Description: hotel酒店监听器
 */
@Slf4j
@Component
public class HotelListener {
    @Autowired
    private IHotelService iHotelService;


    @RabbitListener(bindings = {
            @QueueBinding(value = @Queue(MqConstant.HOTEL_INSERT_QUEUE),
                    exchange = @Exchange(value = MqConstant.HOTEL_EXCHANGE, type = ExchangeTypes.DIRECT),
                    key = MqConstant.HOTEL_INSERT_KEY)
    })
    public void listenHotelInsertAndUpdate(String id) {
        iHotelService.insertById(Long.parseLong(id));
    }

    @RabbitListener(bindings = {
            @QueueBinding(value = @Queue(MqConstant.HOTEL_DELETE_QUEUE),
                    exchange = @Exchange(value = MqConstant.HOTEL_EXCHANGE, type = ExchangeTypes.DIRECT),
                    key = MqConstant.HOTEL_DELETE_KEY)
    })
    public void listenHotelDelete(String id) {
        iHotelService.deleteById(Long.parseLong(id));
    }
}

